package com.jeesite.modules.sys.wx.qy.util;

import com.jeesite.modules.sys.wx.qy.pojo.WXjsTicket;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class WechatAccessToken {
	// 获取企业号access_token
	public final static String company_access_token_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=CORPID&corpsecret=CORPSECRET";

	private static Logger log = LoggerFactory.getLogger(WechatAccessToken.class);

	
	
	public static WXjsTicket getWXjsTicket(String accessToken) {
		WXjsTicket wXjsTicket = null;
		String requestUrl= WXURLUtil.JSAPIURL.replace("ACCESS_TOKEN", accessToken);
		// 发起GET请求获取凭证
		JSONObject jsonObject = WeixinUtil.HttpRequest(requestUrl, "GET", null);
		if (null != jsonObject) {
//			try {
				wXjsTicket = new WXjsTicket();
				wXjsTicket.setJsTicket(jsonObject.getString("ticket"));
				wXjsTicket.setJsTicketExpiresIn(jsonObject.getInt("expires_in"));
//			} catch (JSONException e) {
//				wXjsTicket = null;
//				// 获取wXjsTicket失败
//				log.error("获取wXjsTicket失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
//			}
		}
		return wXjsTicket;
	}
	
	

}